Passed
Pull Request — master (#75)
by Mathieu
01:46
created

IsMaximumTimeSpentReachedOnEdition   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A isSatisfiedBy 0 9 1
1
import {Inject} from '@nestjs/common';
2
import {IEventRepository} from '../Repository/IEventRepository';
3
import {Event} from '../Event.entity';
4
5
export class IsMaximumTimeSpentReachedOnEdition {
6
  constructor(
7
    @Inject('IEventRepository')
8
    private readonly eventRepository: IEventRepository
9
  ) {}
10
11
  public async isSatisfiedBy(event: Event, newTime: number): Promise<boolean> {
12
    const timeSpent = await this.eventRepository.getDayTimeSpentByUser(
13
      event.getUser(),
14
      event.getDate()
15
    );
16
17
    return (
18
      timeSpent - event.getTime() + newTime > Event.MAXIMUM_TIMESPENT_PER_DAY
19
    );
20
  }
21
}
22